package itdfq.ydd.Creational_Pattern.yuanxingmoshi;

import java.io.*;

/**
 * @Author GocChin
 * @Date 2021/3/28 10:47
 * @Blog: itdfq.com
 * @QQ: 909256107
 */
public class World implements Serializable {
    private Annex annex = null;
    public World(){
        this.annex=new Annex();
    }
    /*
            深克隆
     */
    public Object deepClone() throws Exception {
        //讲对象写入流中
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
        objectOutputStream.writeObject(this);
        //从流中取出
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
        ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
        return (objectInputStream.readObject());
    }
    public Annex getAnnex(){
        return this.annex;
    }
    public void watch(){
        System.out.println("打开world，查看world");
    }
}
